<template>
  <div>
    <div class="picker-control__bar stock-bucket__bar">
      <div class="picker-control__bar__cancel" @click="cancel">取消</div>
      <div class="picker-control__bar__tit">{{tit}}</div>
      <div class="picker-control__bar__confirm" @click="confirm">确认</div>
    </div>
    <div class="stock-bucket__container">
      <!-- <div class="stock-bucket__tip">注：可以选择已购买过的水桶进行兑换抵消(线下配送员会逐一核实确认，请依据实际填写)</div> -->
      <div class="stock-bucket__item" v-for="item in list">
        <div class="stock-bucket__item__check">
          <van-checkbox v-model="item.checked"></van-checkbox>
        </div>
        <div class="stock-bucket__item__img" @click="chooseBucket(item)"></div>
        <div class="stock-bucket__item__info" @click="chooseBucket(item)">
          <div class="stock-bucket__item__info__name">{{item.bucketName}}</div>
          <div class="stock-bucket__item__info__price">
            桶价：{{item.bucketPrice}}元
          </div>
        </div>
        <div class="stock-bucket__item__control">
          <van-stepper v-model="item.num" :min="1" :max="item.num" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      bucketList: {
        type: Array,
        default: []
      },
      tit: {
        type: String,
        default: '选择还桶'
      }
    },
    data() {
      return {
        list: []
      }
    },
    mounted() {
      let list = [];
      this.bucketList.forEach(el => {
        let obj = JSON.parse(JSON.stringify(el));
        obj.checked = false;
        list.push(obj);
      });
      this.list = list;
    },
    methods: {
      chooseBucket(item) {
        item.checked = !item.checked;
      },
      cancel() {
        this.$emit('cancel');
      },
      confirm() {
        this.$emit('confirm', this.list);
      }
    }
  }

</script>

<style lang="less" scoped>
  .stock-bucket__bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    box-sizing: border-box;
  }

  .stock-bucket__container {
    position: absolute;
    top: 40px;
    bottom: 0;
    width: 100%;
    overflow: auto;
  }

  .stock-bucket__item {
    display: flex;
    padding: 10px;
    border-bottom: 1px solid #f5f5f5;
    align-items: center;

    .stock-bucket__item__img {
      flex: 0 0 40px;
      height: 40px;
      margin: 0 10px;
      background-image: url('../assets/product.png');
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
    }

    .stock-bucket__item__info {
      flex: 1;

      .stock-bucket__item__info__name {
        font-size: 14px;
      }

      .stock-bucket__item__info__price {
        font-size: 10px;
        color: #999;
      }
    }

    .stock-bucket__item__control {}
  }

  .stock-bucket__tip {
    color: #999;
    font-size: 10px;
    padding: 10px 10px 5px 10px;
  }

</style>
